package com.lht.admin.service;


import com.lht.admin.base.OneParamFunction;
import com.lht.admin.entity.HttpClientDto;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.Map;

/**
 * 跨域业务层接口
 *
 * @author: Frank
 * @date: 2019/09/24 13:51
 * @version: V1.0
 */

public interface HttpClientService {


    /**
     * 执行get请求，不带参数
     *
     * @param url 请求地址
     * @return
     * @throws IOException
     * @throws URISyntaxException
     */
    HttpClientDto doGet(String url) throws IOException, URISyntaxException;

    /**
     * 执行get请求，带参数
     *
     * @param url    请求地址
     * @param params 请求参数
     * @return
     * @throws IOException
     * @throws URISyntaxException
     */
    HttpClientDto doGet(String url, Map<String, Object> params) throws IOException, URISyntaxException;

    /**
     * 执行get请求，带参数
     *
     * @param url    请求地址
     * @param params 请求参数
     * @param fun    可设置httpGet
     * @return
     * @throws IOException
     * @throws URISyntaxException
     */
    HttpClientDto doGet(String url, Map<String, Object> params, OneParamFunction<Void, HttpGet> fun) throws IOException, URISyntaxException;


    /**
     * 执行get请求
     *
     * @param url 请求地址
     * @return
     * @throws IOException
     */
    InputStream doGetReturnStream(String url) throws IOException;

    /**
     * 执行post请求，不带参数
     *
     * @param url 请求地址
     * @return
     * @throws IOException
     */
    HttpClientDto doPost(String url) throws IOException;

    /**
     * 执行post请求，带参数
     *
     * @param url    请求地址
     * @param params 请求参数
     * @return
     * @throws IOException
     */
    HttpClientDto doPost(String url, Map<String, Object> params) throws IOException;

    /**
     * 执行post请求，带参数
     *
     * @param url    请求地址
     * @param params 请求参数
     * @param fun    可设置httpPost
     * @return
     * @throws IOException
     */
    HttpClientDto doPost(String url, Map<String, Object> params, OneParamFunction<Void, HttpPost> fun) throws IOException;

    /**
     * 执行post请求，带json格式字符串
     *
     * @param url    请求地址
     * @param params 请求参数
     * @return
     * @throws IOException
     */
    HttpClientDto doPostJson(String url, String params) throws IOException;

    /**
     * 带token执行post请求，带xml格式字符串
     *
     * @param url    请求地址
     * @param params 请求参数
     * @param fun    可设置httpPost
     * @return
     * @throws IOException
     */
    HttpClientDto doPostJson(String url, String params, OneParamFunction<Void, HttpPost> fun) throws IOException;

    /**
     * 执行post请求，带json格式字符串
     *
     * @param url    请求地址
     * @param params 请求参数
     * @return
     * @throws IOException
     */
    InputStream doPostJsonReturnStream(String url, String params) throws IOException;

    /**
     * 执行post请求，带xml格式字符串
     *
     * @param url 请求地址
     * @param xml 请求参数
     * @return
     * @throws IOException
     */
    HttpClientDto doPostXml(String url, String xml) throws IOException;

    /**
     * 执行post请求，带xml格式字符串
     *
     * @param url     请求地址
     * @param params  请求参数
     * @param charset 请求编码
     * @return
     * @throws IOException
     */
    HttpClientDto doPostXml(String url, String params, String charset) throws IOException;

    /**
     * 执行post请求，带xml格式字符串
     *
     * @param url     请求地址
     * @param params  请求参数
     * @param charset 请求编码
     * @param fun     可设置httpPost
     * @return
     * @throws IOException
     */
    HttpClientDto doPostXml(String url, String params, String charset, OneParamFunction<Void, HttpPost> fun) throws IOException;

    /**
     * 执行post请求，带xml格式字符串,需要携带证书和密钥
     *
     * @param url          请求地址
     * @param xml          报文
     * @param certFilePath 证书路径
     * @param keyPassword  密钥
     * @return
     * @throws NoSuchAlgorithmException
     * @throws KeyStoreException
     * @throws IOException
     * @throws CertificateException
     * @throws KeyManagementException
     * @throws UnrecoverableKeyException
     */
    HttpClientDto doPostXmlByCertAndKeyPassword(String url, String xml, String certFilePath, char[] keyPassword) throws NoSuchAlgorithmException, KeyStoreException, IOException, CertificateException, KeyManagementException, UnrecoverableKeyException;

    /**
     * 执行post请求，带xml格式字符串,需要携带证书和密钥
     *
     * @param url          请求地址
     * @param xml          报文
     * @param certFilePath 证书路径
     * @param keyPassword  密钥
     * @param fun          可设置httpPost
     * @return
     * @throws NoSuchAlgorithmException
     * @throws KeyStoreException
     * @throws IOException
     * @throws CertificateException
     * @throws KeyManagementException
     * @throws UnrecoverableKeyException
     */
    HttpClientDto doPostXmlByCertAndKeyPassword(String url, String xml, String certFilePath, char[] keyPassword, OneParamFunction<Void, HttpPost> fun) throws NoSuchAlgorithmException, KeyStoreException, IOException, CertificateException, KeyManagementException, UnrecoverableKeyException;

}
